#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2014-08-22 01:14:23
# @Author  : shitao.tommy (hero007asd@gmail.com)
# @Link    : http://example.org
# @Version : $Id$

from lib import log
from tornado import httpclient

def get_url_body(url):
    http_client = httpclient.HTTPClient()
    # http_client = httpclient.AsyncHTTPClient()
    response = ''
    try:
        response = http_client.fetch(url)
        # response = http_client.fetch(url, parse)
    except Exception as e:
        log.log_exception('get_body', e)
        response = '-1'
    http_client.close()
    return response.body

def parse(response):
    if response.error:
        log.log_exception('parse', response.error)
        return None
    else:
        return response.body

